<?php

/**
 * Maikuro CMS
 *
 * LICENSE:
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * The license is bundled with this package in the file LICENSE.txt.
 * You may also obtain a copy of the License at this URL:
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * @copyright  Copyright (c) 2010, Jonathan Hedrén
 * @author     Jonathan Hedrén <jonathan.hedren@gmail.com>
 * @license    http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
 */

?>

<h1><?php echo $title; ?></h1>
<form action="" method="post" id="user-form">
    <div class="container">
        <fieldset>
            <legend><?php echo Translator::translate('Administrator user data'); ?></legend>
            <?php HtmlBinder::hiddenFor($model->administrator, 'id'); ?>
            <div class="field text">
                <?php 
                    HtmlBinder::labelFor($model->administrator, 'username');
                    HtmlBinder::textBoxFor($model->administrator, 'username');
                    HtmlBinder::validationMessagesFor($model->administrator, 'username');
                ?>
            </div>
            <div class="field email">
                <?php 
                    HtmlBinder::labelFor($model->administrator, 'email');
                    HtmlBinder::inputFor('email', $model->administrator, 'email');
                    HtmlBinder::validationMessagesFor($model->administrator, 'email');
                ?>
            </div>
            <div class="field password">
                <?php
                    HtmlBinder::labelFor($model->administrator, 'password');
                    HtmlBinder::textBoxFor($model->administrator, 'password');
                    HtmlBinder::validationMessagesFor($model->administrator, 'password');
                ?>
            </div>
        </fieldset>
    </div>
    <div id="administrator-system-permissions" class="container">
        <fieldset>
            <legend><?php echo Translator::translate('System permissions'); ?></legend>
            <?php foreach ($model->systemPermissions as $systemPermission):
                    $key = $systemPermission->subject;
                    if (isset($model->administrator->permissions[$key])): ?>
                    <div class="field select">
                        <?php HtmlBinder::labelFor($model->administrator->permissions[$key], 'accessLevel', $systemPermission->title); ?>
                        <?php HtmlBinder::selectFor($model->administrator->permissions[$key], 'accessLevel', $model->accessLevels); ?>
                    </div>
            <?php   endif;
                endforeach; ?>
        </fieldset>
    </div>
    <div id="administrator-content-permissions" class="container">
        <fieldset>
            <legend><?php echo Translator::translate('Site content permissions'); ?></legend>
            <?php foreach ($model->sites as $site): ?>
            <fieldset>
                <legend><?php echo $site->name; ?></legend>
            <?php foreach ($model->sitePermissions as $sitePermission):
                    $key = $site->id . '/' . $sitePermission->subject;
                    if (isset($model->administrator->permissions[$key])): ?>
                <div class="field select">
                    <?php HtmlBinder::labelFor($model->administrator->permissions[$key], 'accessLevel', $sitePermission->title); ?>
                    <?php HtmlBinder::selectFor($model->administrator->permissions[$key], 'accessLevel', $model->accessLevels); ?>
                </div>
            <?php   endif;
                endforeach; ?>
            </fieldset>
            <?php endforeach; ?>
        </fieldset>
    </div>

    <div class="actions container">
        <input type="submit" class="neutral-action" name="cancel" value="<?php echo Translator::translate('Cancel'); ?>" />
        <input type="submit" class="positive-action" name="save" value="<?php echo Translator::translate('Save'); ?>" />
    </div>
</form>
